#include "watcard.h"
#include "PRNG.h"

// WATCard:

WATCard::WATCard(unsigned int newid) {
	id = newid;
	fund = 0;
}
void WATCard::addFund(unsigned int amount) {
	fund = fund + amount;
}
void WATCard::subFund(unsigned int amount) {
	fund = fund - amount;
}
unsigned int WATCard::getFund() {
	return fund;
}
unsigned int WATCard::getId() {
	return id;
}



// WATCardOffice:
WATCardOffice::WATCardOffice( Printer &prt ) {
   this->prt = &prt;  
  prt.print(Printer::WATCardOffice, 'S');
}
WATCard* WATCardOffice::create( unsigned int id, unsigned int amount ) {
  prt->print(Printer::WATCardOffice, 'C', id, amount);
	WATCard *card = new WATCard(id);
  card->addFund(amount);
	return card;
}
void WATCardOffice::transfer( unsigned int id, unsigned int amount, WATCard &card ) {
  prt->print(Printer::WATCardOffice, 't', id, amount);
	if(prng(3) == 0) {
		amount /= 2;
	}
  card.addFund(amount);
   prt->print(Printer::WATCardOffice, 'T', id, amount);
}

WATCardOffice::~WATCardOffice() {
  prt->print(Printer::WATCardOffice, 'F');
}